package com.ruoyi.gbase.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gbase.domain.TLlLog;
import com.ruoyi.gbase.service.ITLlLogService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 拉链维护Controller
 * 
 * @author yys
 * @date 2023-11-30
 */
@Controller
@RequestMapping("/gbase/LLlog")
public class TLlLogController extends BaseController
{
    private String prefix = "gbase/LLlog";

    @Autowired
    private ITLlLogService tLlLogService;

    @RequiresPermissions("gbase:LLlog:view")
    @GetMapping()
    public String LLlog()
    {
        return prefix + "/LLlog";
    }

    /**
     * 查询拉链维护列表
     */
    @RequiresPermissions("gbase:LLlog:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TLlLog tLlLog)
    {
        startPage();
        List<TLlLog> list = tLlLogService.selectTLlLogList(tLlLog);
        return getDataTable(list);
    }

    /**
     * 导出拉链维护列表
     */
    @RequiresPermissions("gbase:LLlog:export")
    @Log(title = "拉链维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TLlLog tLlLog)
    {
        List<TLlLog> list = tLlLogService.selectTLlLogList(tLlLog);
        ExcelUtil<TLlLog> util = new ExcelUtil<TLlLog>(TLlLog.class);
        return util.exportExcel(list, "LLlog");
    }

    /**
     * 新增拉链维护
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存拉链维护
     */
    @RequiresPermissions("gbase:LLlog:add")
    @Log(title = "拉链维护", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TLlLog tLlLog)
    {
        tLlLog.setId(tLlLog.getTabschema()+"_"+tLlLog.getTabname());
        return toAjax(tLlLogService.insertTLlLog(tLlLog));
    }

    /**
     * 修改拉链维护
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        TLlLog tLlLog = tLlLogService.selectTLlLogById(id);
        mmap.put("tLlLog", tLlLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存拉链维护
     */
    @RequiresPermissions("gbase:LLlog:edit")
    @Log(title = "拉链维护", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TLlLog tLlLog)
    {
        if(!tLlLog.getId().equals(tLlLog.getTabschema()+"_"+tLlLog.getTabname())){
            //说明修改了模式和表名
            tLlLog.setId(tLlLog.getTabschema()+"_"+tLlLog.getTabname());
            return toAjax(tLlLogService.insertTLlLog(tLlLog));
        }else{
            tLlLog.setId(tLlLog.getTabschema()+"_"+tLlLog.getTabname());
            return toAjax(tLlLogService.updateTLlLog(tLlLog));
        }
    }

    /**
     * 删除拉链维护
     */
    @RequiresPermissions("gbase:LLlog:remove")
    @Log(title = "拉链维护", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tLlLogService.deleteTLlLogByIds(ids));
    }
}
